package pt.mdc.android.mysensors;

import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;

public class Sensors extends ListActivity {
		
	private SensorManager mySensorManager;
	private List<Sensor> sensors;
 
	/** Called when the activity is first created. */
	public void onCreate(Bundle icicle) {
	
		super.onCreate(icicle);
		
		// get sensor manager instance
		mySensorManager = (SensorManager)getSystemService(
	            Context.SENSOR_SERVICE);
		
		// get all sensors
		sensors = mySensorManager.getSensorList(Sensor.TYPE_ALL);
		
		// build array of sensor names
		String[] names = new String[sensors.size()];
		for (int i = 0; i < sensors.size();i++)
			names[i] = sensors.get(i).getName();
		
		// Show sensors in ListView
		this.setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_checked, names));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		Bundle bundle = new Bundle();
		bundle.putInt("sensor_id", position);
		
		
		Intent newIntent = new Intent(this.getApplicationContext(), SensorDetails.class);
		newIntent.putExtras(bundle);
		startActivityForResult(newIntent, 0);		
	}	
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
	}
}